#define _CRT_SECURE_NO_WARNINGS 1
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'

void solve() {
	int n, m; cin >> n >> m;
	vector<ll> a(n + 1), b(n + 1);
	for (int i = 1; i <= n; i++) cin >> a[i];
	for (int i = 1; i <= n; i++) cin >> b[i];
	ll sum = 0, ans = 1e18;
	for (int i = m + 1; i <= n; i++) sum += min(a[i], b[i]);
	for (int i = m; i >= 1; i--) {
		ans = min(ans, sum + a[i]);
		sum += min(a[i], b[i]);
	}
	cout << ans << endl;
}

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int t; cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}